/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package location.security;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import java.util.Map;
import locations.actions.CargarBaseAction;

public class LoginInterceptor implements Interceptor {

    private static final long serialVersionUID = 1L;

    public String intercept(ActionInvocation invocation) throws Exception {

        final ActionContext context = invocation.getInvocationContext();
        Map<String, Object> session = context.getSession();
        if (!(invocation.getAction().getClass().equals(LoginValidationAction.class) || (invocation.getAction().getClass().equals(CargarBaseAction.class)))) {
            if (!session.containsKey("usuario")) {
                return "login";
            }               
        }

        return invocation.invoke();
    }

    public void destroy() {
    }

    public void init() {
    }
}
